|
|
 |
|
|
|
|
Then
j = (v1y * (X - px) + v1x * (py - Y)) / _
(v1y * v2x - v2y * v1x)
i = (X - px - v2x * j) / v1x
ElseIf (Abs(v1y) > 0.001) And _
(Abs(v1z * v2y - v2z * v1y) > 0.001) _
Then
j = (v1z * (Y - py) + v1y * (pz - Z)) / _
(v1z * v2y - v2z * v1y)
i = (Y - py - v2y * j) / v1y
Else
j = (v1x * (Z - pz) + v1z * (px - X)) / _
(v1x * v2z - v2x * v1z)
i = (Z - pz - v2z * j) / v1z
End If
' See if the point is ok. If (i < 0) Or (j < 0) Or _
(i > NumSquares1) Or (j > NumSquares2) _
Then ' Not on the area of interest. RayTraceable_FindT = -1
Exit Function
ElseIf (Int(i) + Int(j)) Mod 2 <> 0 Then ' Not on a drawn square. RayTraceable_FindT = -1
Exit Function
Else ' We had a hit. If direct_calculation Then HadHit = True
RayTraceable_FindT = t
End If
End Function |
|
|
|
|
|
|
|
|
Figure 17.16 shows program VBRay displaying a sphere surrounded by six RayCheckerboard objects. With a little work, you could produce a similar image using RayPolygon objects instead of RayCheckerboard objects. That would require 78 separate polygons instead of 6 checkerboards so it would slow the program greatly. |
|
|
|
|
|
|
|
|
This method of mapping a point's (x, y, z) coordinates into (i, j) coordinates on the plane is similar to texture mapping described later in this chapter. In texture mapping, the transformed coordinates are used to decide what color to make the pixel rather than to decide whether the point lies on the object. |
|
|
|
|
|
|
|
|
The round cylinders considered here consist of all the points that are a fixed distance from a line called the cylinder's axis. You can define a cylinder by specifying its radius and two points along its axis. If you want the cylinder to have a finite length, the two |
|
|
|
|
|